home *** CD-ROM | disk | FTP | other *** search
/ Popular Request / By Popular Request (Arsenal Computer)(SysOptics Distribution System).ISO / amiga3 / nwgccstr.lha / source.lha / startup / motorola.s < prev    next >
Text File  |  1994-03-13  |  3KB  |  101 lines

  1. #if !defined(CRT0) && !defined(BCRT0) && !defined(RCRT0)
  2. #define CRT0
  3. #endif
  4. #ifdef CRT0
  5. ; normal (large data model) startup code
  6. #endif
  7. #ifdef BCRT0
  8. ; base relative (short data model) startup code
  9. #endif
  10. #ifdef RCRT0
  11. ; resident (short data model) startup code
  12. #endif
  13.   SECTION text,CODE
  14.   even
  15.   PUBLIC ___amain
  16.   PUBLIC ___aexit
  17. #ifndef RCRT0
  18.   PUBLIC _geta4
  19. #endif
  20.  
  21.   movem.l d1-d7/a0-a6,-(a7)      ; push registers
  22. #ifdef BCRT0
  23.   jsr      _geta4         ; set global data segment pointer
  24. #endif
  25. #ifdef RCRT0
  26.   movea.l 4,a6             ; get SysBase            ->a6
  27.   movea.l a0,a2          ; store argument        ->a2
  28.   move.l  #___data_size,d2     ;
  29.   addi.l  #___bss_size,d2     ; global data segment size ->d2
  30.   move.l  d2,d0          ; size
  31.   moveq.l #0,d1          ; MEMF_ANY
  32.   jsr      -198(a6)               ; AllocMem
  33.   movea.l d0,a4          ; new global data segment  ->a4
  34.   bne.b   gotit          ; yes ?
  35.   moveq.l #20,d0         ; oh, dear
  36.   bra.b   error          ;
  37. gotit:                 ;
  38.   lea.l   ___a4_init,a3      ; old global data segment pointer
  39.   suba.w  #32766,a3         ; old global data segment  ->a3
  40.   move.l  d2,d0          ; size
  41.   movea.l a3,a0          ; old
  42.   movea.l a4,a1          ; new
  43.   jsr      -624(a6)               ; CopyMem
  44.   move.l  a3,d0          ;
  45.   sub.l   a4,d0          ; old-new            ->d0
  46.   movea.l #___datadata_relocs,a0 ; pointer relocation table ->a0
  47.   move.l  (a0)+,d1               ; number of pointers       ->d1
  48.   beq.b   loopend         ; none ?
  49. loop:                 ;
  50.   movea.l (a0)+,a1               ; get offset of next pointer
  51.   sub.l   d0,0(a1,a4.l)          ; and fix it
  52.   subq.l  #1,d1          ;
  53.   bne.b   loop             ; ready ?
  54. loopend:             ;
  55.   move.l  a4,-(a7)               ; push memory address
  56.   move.l  d2,-(a7)               ; and size
  57.   adda.w  #32766,a4         ; get new global data segment pointer
  58.   movea.l a2,a0          ; remember argument
  59. #endif
  60. #ifdef CRT0
  61.   move.l  a7,stackpointer     ; store stackpointer
  62. #else
  63.   move.l  a7,-32766(a4)          ; store stackpointer
  64. #endif
  65.   move.l  a0,-(a7)               ; push Argument
  66.   jsr      ___amain         ; call __amain(), does not return
  67. ___aexit:
  68. #ifdef RCRT0
  69.   move.l  4(a7),d2               ; remember returncode
  70. #else
  71.   move.l  4(a7),d0               ; get returncode
  72. #endif
  73. #ifdef CRT0
  74.   movea.l stackpointer,a7     ; set stackpointer
  75. #else
  76.   movea.l -32766(a4),a7          ; set stackpointer
  77. #endif
  78. #ifdef RCRT0
  79.   movea.l 4,a6             ; get SysBase
  80.   move.l  (a7)+,d0               ; pop memory size
  81.   movea.l (a7)+,a1               ; and address
  82.   jsr      -210(a6)               ; FreeMem()
  83.   move.l  d2,d0          ; get returncode
  84. error:                 ;
  85. #endif
  86.   movem.l (a7)+,d1-d7/a0-a6      ; pop registers
  87. #ifdef CRT0
  88. _geta4:              ;
  89. #endif
  90.   rts                 ;
  91. #ifdef BCRT0
  92. _geta4:              ; Set global-data segment pointer
  93.   lea.l   ___a4_init,a4      ;
  94.   rts                 ;
  95. #endif
  96.  
  97.   SECTION readwrite,DATA
  98.   even
  99. stackpointer:
  100.   dc.l      0
  101.